<?php
	class mresponsable extends Model {
		private $mTableName = 'GN_Responsables';
	
		public function __construct() 
		{
			parent::Model();
			$this->load->database();
		}
		 
		function CreateEstatus($nombre) 
		{
		
			$data = array( 
				'NombreResponsable'   => $nombre);
			
			$this->db->insert($this->mTableName, $data);
			return $this->LoadEstatusById($this->db->insert_id());
		}
		
		function UpdateEstatus($estatus) 
		{
			$nombre = $estatus->GetNombre();
			
			
			if (empty($nombre) )
				return false;
			
			$data = array(
				'NombreResponsable'    	=> $nombre
								
			);
			
			$this->db->where('IdResponsable', $estatus->getIdEstatus());
        	$this->db->update($this->mTableName, $data);
			
			return true;
		}
		
		function LoadEstatusById($id_estatus) {
			$qresult = $this->db->get_where($this->mTableName, array('IdResponsable' => $id_estatus));

			if ($qresult->num_rows() == 0)
				return false;
	
			return new dresponsable($qresult->row());
		}
		
		function LoadResponsable($start = false, $offset = false, $sortname = false, $sortorder = false) {
			
			
			if($offset != false)
				$this->db->limit($offset, $start);

			if($sortname != false && $sortorder != false) {
				$this->db->order_by($sortname, $sortorder);
			}
	
			$result = $this->db->get_where($this->mTableName);
	
			return $this->GetResponsableArrayFromQueryResult($result);
		}
		
		function GetCount() {
			return count($this->LoadResponsable());
		}
		
		function GetResponsableArrayFromQueryResult($result) {
			if ($result->num_rows() == 0)
				return false;
	
			$estatus_arr = array();
	
			foreach ($result->result() as $record) {
				$estatus_arr[] = new dresponsable($record);
			}
	
			return $estatus_arr;
    	}
		

		
		function Delete($id_estatus) {
			$return = $this->db->delete($this->mTableName, array('IdResponsable' => $id_estatus));
			return $return;
		}
	}
	
	class dresponsable {
		private $mIdresponsabe = 0;
		
		private $mresponsable = "";
		
		function __construct($object) {
			$this->setIdEstatus($object->IdResponsable);
			$this->setNombre($object->NombreResponsable);
	
		}
		
		private function setIdEstatus($id_estatus) {
			$this->mIdresponsabe = $id_estatus;
		}
		
		function getIdEstatus() {
			return $this->mIdresponsabe;
		}
		
		function setNombre($nombre) {
			$this->mresponsable = $nombre;
		}
		
		function getNombre() {
			return $this->mresponsable;
		}	
	}
?>